# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=set
_pkgname=social-engineer-toolkit
pkgver=8.0.3
pkgrel=8
epoch=1
groups=('blackarch' 'blackarch-social' 'blackarch-exploitation')
pkgdesc='Social-engineer toolkit. Aimed at penetration testing around Social-Engineering.'
arch=('any')
url='https://github.com/trustedsec/social-engineer-toolkit/tags'
license=('BSD')
makedepends=('git')
depends=('python' 'python-beautifulsoup4' 'python-pexpect' 'python-pycryptodome'
         'java-environment' 'python-requests' 'impacket' 'python-pefile'
         'python-pillow' 'python-qrcode')
optdepends=('ettercap: DNS spoofing and ARP cache poisoning capabilities'
            'sendmail: email address spoofing'
            'python-pefile: advanced AV evasion via hijacking a legit digital certificate'
            'apache: increase speed of web attack vectors'
            'openssl: create self-signed SSL certificates'
            'xterm: default terminal for SET command center'
            'upx: executable packer for better AV evasion'
            'aircrack-ng: rouge access point capabilities'
            'dsniff: DNS spoofing capabilities'
            'python-cryptography: Encrypted communications'
            'metasploit: metasploit exploit payloads')
options=('!strip')
source=("https://github.com/trustedsec/$_pkgname/archive/$pkgver.tar.gz")
sha512sums=('c5f18b8d624bac57df24223a0b6885685847be15a1d34b24e18015b5e555b8722654ca6432c6f7211c3bbc422bedd24e25f1f67d76b571b448ee918b0f1c9dbf')
backup=('usr/share/set/config/set_config')

prepare() {
  cd "$_pkgname-$pkgver"

  # Fix shebands in all se*
  sed -i -e "s|#![ ]*/usr/bin/python2$|#!/usr/bin/python|" \
      -i -e "s|#![ ]*/usr/bin/env python2$|#!/usr/bin/env python|" \
      se*

  # Fix tab-space inconsistencies.
  sed -i 's/\t/    /g' se*

  # Fix all calls to 'python-pycrypto' change to 'python-crypto'
  grep -Rl python-pycrypto ./ | xargs sed -i 's|python-pycrypto|python-crypto|g'

  cd "src/core/"

  ## Check if Metasploit is installed
  if [ -d /usr/share/metasploit ]; then
    sed -i 's|/opt/metasploit/apps/pro/msf3|/usr/share/metasploit|g' \
      config.baseline
  fi

  ## Apply httpd directory
  sed -i 's|/var/www|/srv/http|g' config.baseline

  ## Set proper dnsspoof bin
  sed -i 's|/usr/local/sbin/dnsspoof|/usr/bin/dnsspoof|g' config.baseline

  ## Set proper airbase-ng bin
  sed -i 's|/usr/local/sbin/airbase-ng|/usr/bin/airbase-ng|g' config.baseline
}

package() {
  cd "$_pkgname-$pkgver"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"
  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"

  cp --no-preserve=ownership -R * "$pkgdir/usr/share/$pkgname/"
  cp --no-preserve=ownership -R readme/* "$pkgdir/usr/share/doc/$pkgname/"

  # Fix shebangs in all .py files
  sed -i -e "s|/usr/bin/python2|/usr/bin/python2|" \
      -i -e "s|/usr/bin/env python2|/usr/bin/env python|" \
      $(find "${pkgdir}" -type f)

  # Joint script to handle default configuration.
  cat > "$pkgdir/usr/bin/setoolkit" << EOF
#!/bin/sh

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

cd /usr/share/set
./setoolkit
EOF

  chmod +x "$pkgdir/usr/bin/setoolkit"
}

